package com.syt.user.api;

import com.syt.commer.Result;
import com.syt.commer.utils.AuthContextHolder;
import com.syt.entity.model.user.UserInfo;
import com.syt.entity.vo.user.LoginVo;
import com.syt.entity.vo.user.UserAuthVo;
import com.syt.user.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@Api(tags = "用户登录")
@RestController
@RequestMapping("/api/user")
public class UserInfoApiController {

    @Autowired// 登陆注册的方法
    private UserInfoService userInfoService;


    // 根据手机号进行登陆 用户手机号登陆接口
    @ApiOperation(value = "用户登录功能")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo, HttpServletRequest request){

       Map<String, Object> info= userInfoService.loginUser(loginVo);

       return Result.ok(info);

    }
    
    
    
    @ApiOperation(value = "qq邮箱用户登录")
    @PostMapping("loginEmail")
    public Result loginEmail(@RequestBody LoginVo loginVo, HttpServletRequest request) {
//        loginVo.setIp(IpUtil.getIpAddr(request));
        Map<String, Object> info = userInfoService.loginEmail(loginVo);
        return Result.ok(info);
    }

    
    
    
    //用户认证接口
    @ApiOperation(value = "用户认证接口")
    @PostMapping("auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request) {
        //传递两个参数，第一个参数用户id，第二个参数认证数据vo对象
        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);
        return Result.ok();
    }

    //获取用户id信息接口
    @ApiOperation(value = "获取用户id接口")
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request) {
        Long userId = AuthContextHolder.getUserId(request);
        UserInfo userInfo = userInfoService.getById(userId);
        return Result.ok(userInfo);
    }


}
